<?php
namespace api\modules\v1\controllers;

use Yii;
use api\components\ApiController;
use api\modules\v1\models\Order;
use api\modules\v1\models\OrderEvaluate;

/**
 * 交易流程控制器
 * @author WJ
 */
class OrderController extends ApiController
{
    /**
     * 接下挂买需求
     * @author WJ
     */
    public function actionAcceptBuy()
    {
        $params = Yii::$app->request->post();
        $model = new Order();
        $model->setScenario(Order::SCENARIO_ACCEPT_BUY);
        $model->load($params, '');
        if ($result = $model->acceptBuy()) {
            return ['message' => '接单成功，请等待多方确认', 'data' => $result];
        }
    }

    /**
     * 订单列表
     * @author ZCY
     */
    public function actionList()
    {
        $params = Yii::$app->request->post();
        $model = new Order();
        $model->setScenario(Order::SCENARIO_LIST);
        $model->load($params, '');
        if ($result = $model->orderlist()) {
            return ['message' => '订单列表获取成功', 'data' => $result];
        }
    }

    /**
     * 接下挂卖需求
     * @author WJ
     */
    public function actionAcceptSell()
    {
        $params = Yii::$app->request->post();
        $model = new Order();
        $model->setScenario(Order::SCENARIO_ACCEPT_SELL);
        $model->load($params, '');
        if ($result = $model->acceptSell()) {
            return ['message' => '接单成功，请等待发布方确认', 'data' => $result];
        }
    }

    /**
     * 选择经纪人
     * @author WJ
     */
    public function actionSelectBroker()
    {
        $params = Yii::$app->request->post();
        $model = new Order();
        $model->setScenario(Order::SCENARIO_SELECT_BROKER);
        $model->load($params, '');
        if ($result = $model->selectBroker()) {
            return ['message' => '委任发送成功,等待对方确认', 'data' => $result];
        }
    }

    /**
     * 确认订单
     * @author CGA
     */
    public function actionConfirm()
    {
        $params = Yii::$app->request->post();
        $model = new Order();
        $model->setScenario(Order::SCENARIO_CONFIRM);
        $model->load($params, '');
        if ($result = $model->confirm()){
            return ['message' => '操作成功'];
        }
    }

    /**
     * 拒绝订单
     * @author CGA
     */
    public function actionRefuse()
    {
        $params = Yii::$app->request->post();
        $model = new Order();
        $model->setScenario(Order::SCENARIO_REFUSE);
        $model->load($params, '');
        if ($result = $model->refuse()){
            return ['message' => '已拒绝订单', 'data' => $result];
        }
    }

    /**
     * 订单详情
     * @author ZCY
     */
    public function actionInfo()
    {
        $params = Yii::$app->request->post();
        $model = new Order();
        $model->setScenario(Order::SCENARIO_INFO);
        $model->load($params, '');
        if ($result = $model->orderinfo()) {
            return ['message' => '订单详情获取成功', 'data' => $result];
        }
    }

    /**
     * 买方确认转款
     * @author WJ
     */
    public function actionBuyerTransfer()
    {
        $params = Yii::$app->request->post();
        $model = new Order();
        $model->setScenario(Order::SCENARIO_BUYER_TRANSFER);
        $model->load($params, '');
        if ($result = $model->buyerTransfer()) {
            return ['message' => '买方确认已转款', 'data' => $result];
        }
    }

    /**
     * 卖方确认收款
     * @author CGA
     */
    public function actionReceiveMoney()
    {
        $params = Yii::$app->request->post();
        $model = new Order();
        $model->setScenario(Order::SCENARIO_RECEIVE_MONEY);
        $model->load($params, '');
        if ($result = $model->sellerrRceiveMoney()) {
            return ['message' => '卖方确认已收款'];
        }
    }
    
    
    /**
     * 评价
     * @author ZCY
     */
    public function actionEvaluate()
    {
        $params = Yii::$app->request->post();
        $model = new OrderEvaluate();
        $model->setScenario(OrderEvaluate::SCENARIO_EVALUATE);
        $model->load($params, '');
        if ($result = $model->evaluate()) {
            return ['message' => '用户评价成功', 'data' => $result];
        }
    }
    
    /**
     * 评价列表
     * @author ZCY
     */
    public function actionEvaluateList()
    {
        $params = Yii::$app->request->post();
        $model = new OrderEvaluate();
        $model->setScenario(OrderEvaluate::SCENARIO_LIST);
        $model->load($params, '');
        if ($result = $model->evaluatelist()) {
            return ['message' => '用户评价信息获取成功', 'data' => $result];
        }
    }
    
    /**
     * 评价列表
     * @author ZCY
     */
    public function actionRecentList()
    {
        $params = Yii::$app->request->post();
        $model = new Order();
        $model->setScenario(Order::SCENARIO_RECENT_LIST);
        $model->load($params, '');
        if ($result = $model->recentorderlist()) {
            return ['message' => '最近成交列表获取成功', 'data' => $result];
        }
    }
   
    
    
}
